package com.bkhc.product.api;

import com.bkhc.common.annotation.ApiOperation;
import com.bkhc.common.annotation.ApiPackage;
import com.bkhc.common.annotation.AuditLog;
import com.bkhc.common.enu.OperationEnum;
import com.bkhc.common.util.response.ResultJson;
import com.bkhc.product.entity.Spec;
import com.bkhc.product.entity.SpecRange;
import com.bkhc.product.service.SpecService;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author pcq
 * @date 2021/6/20 17:57
 */
@RestController
@RequestMapping("/spec")
@Api("规格管理服务")
@ApiPackage(code="spec-api",name="规格管理服务",description = "后台规格管理维护操作接口")
public class SpecController extends CommonController{
    @Autowired
    private SpecService specSerivce;

    @ApiOperation(code="querySpec",name="查询规格",description = "查询规格")
    @AuditLog(object="Spec",operation = "查询规格",type = OperationEnum.query)
    @RequestMapping(path = "/list/{pageNum}/{pageSize}",method = RequestMethod.POST)
    public ResultJson<?> getSpecs(@RequestBody(required=false) Spec spec, @PathVariable(name="pageNum") int pageIndex, @PathVariable(name="pageSize") int pageSize) {
        ResultJson<?> res = specSerivce.querySpecs(spec, pageIndex, pageSize);
        return res;
    }

    @ApiOperation(code="availablespec",name="规格可用",description = "规格可用")
    @AuditLog(object="Spec",operation = "规格可用",type = OperationEnum.update)
    @RequestMapping(path = "/available",method = RequestMethod.POST)
    public ResultJson<?> availableSpec(@RequestBody(required=true) Spec spec) {
        spec.setStatus("1");
        ResultJson<?> res = specSerivce.updateSpcStatus(spec);
        return res;
    }
    @ApiOperation(code="disableSpec",name="规格禁用",description = "规格禁用")
    @AuditLog(object="Spec",operation = "规格禁用",type = OperationEnum.update)
    @RequestMapping(path = "/disable",method = RequestMethod.POST)
    public ResultJson<?> disableSpec(@RequestBody(required=true) Spec spec) {
        spec.setStatus("0");
        ResultJson<?> res = specSerivce.updateSpcStatus(spec);
        return res;
    }

    @ApiOperation(code="addSpec",name="增加规格",description = "增加规格")
    @AuditLog(object="Spec",operation = "增加规格",type = OperationEnum.add)
    @RequestMapping(path = "/add",method = RequestMethod.POST)
    public ResultJson<?> addSpec(@RequestBody(required=true) Spec spec) {
        ResultJson<?> res = specSerivce.addSpecs(spec);
        return res;
    }

    @ApiOperation(code="updateSpec",name="更新规格",description = "更新规格")
    @AuditLog(object="updateSpec",operation = "更新规格",type = OperationEnum.update)
    @RequestMapping(path = "/update",method = RequestMethod.POST)
    public ResultJson<?> updateSpec(@RequestBody(required=true) Spec spec) {
        ResultJson<?> res = specSerivce.updateSpec(spec);
        return res;
    }

    @ApiOperation(code="deleteSpec",name="刪除规格",description = "刪除规格")
    @AuditLog(object="deleteSpec",operation = "刪除规格",type = OperationEnum.delete)
    @RequestMapping(path = "/delete",method = RequestMethod.POST)
    public ResultJson<?> deleteSpec(@RequestBody(required=true) Spec spec) {
        ResultJson<?> res = specSerivce.deleteSpec(spec);
        return res;
    }

    @ApiOperation(code="addSpecRange",name="增加規格值",description = "增加規格值")
    @AuditLog(object="addSpecRange",operation = "增加規格值",type = OperationEnum.add)
    @RequestMapping(path = "/range/add",method = RequestMethod.POST)
    public ResultJson<?> addSpecRange(@RequestBody(required=true) SpecRange range) {
        ResultJson<?> res = specSerivce.addSpecRange(range);
        return res;
    }

    @ApiOperation(code="querySpecRange",name="查看一个規格的参数值",description = "查看一个規格的参数值")
    @AuditLog(object="SpecRang",operation = "查看一个規格的参数值",type = OperationEnum.query)
    @RequestMapping(path = "/range/list",method = RequestMethod.POST)
    public ResultJson<?> querySpecRange(@RequestBody(required=true) SpecRange range) {
        ResultJson<?> res = specSerivce.querySpecRange(range);
        return res;
    }

    @ApiOperation(code="deleteSpecRange",name="刪除規格值",description = "刪除規格值")
    @AuditLog(object="deleteSpecRange",operation = "刪除規格值",type = OperationEnum.delete)
    @RequestMapping(path = "/range/delete",method = RequestMethod.POST)
    public ResultJson<?> deleteSpecRange(@RequestBody(required=true) SpecRange range) {
        ResultJson<?> res = specSerivce.deleteSpecRange(range);
        return res;
    }

    @ApiOperation(code="availableRangValue",name="参数值可用",description = "参数值可用")
    @AuditLog(object="availableRangValue",operation = "参数值可用",type = OperationEnum.update)
    @RequestMapping(path = "/range/available",method = RequestMethod.POST)
    public ResultJson<?> availableRangValue(@RequestBody(required=true) SpecRange range) {
        range.setStatus("1");
        ResultJson<?> res = specSerivce.updateRangValue(range);
        return res;
    }
    @ApiOperation(code="disableRangValue",name="参数值禁用",description = "参数值禁用")
    @AuditLog(object="disableRangValue",operation = "参数值禁用",type = OperationEnum.update)
    @RequestMapping(path = "/range/disable",method = RequestMethod.POST)
    public ResultJson<?> disableRangValue(@RequestBody(required=true) SpecRange range) {
        range.setStatus("0");
        ResultJson<?> res = specSerivce.updateRangValue(range);
        return res;
    }
}
